//获取应用实例
// var WxSearch = require('../../wxSearch/wxSearch.js');
var Util = require('../../utils/util.js');
var utilMd5 = require('../../utils/md5.js');
var app = getApp(), that;
Page({
  data: {

    inputShowed: false,
    inputVal: "",
    phoneval: '',
    /**
     * 页面配置
     */

    winWidth: 0,
    winHeight: 0,
    // tab切换 
    currentTab: 0,
    mobile: "",
    appkey: "",
    open: false,
    Color: 'Red',
    result: [],
    index: 0,
    windowHeight: 0,
    windowWidth: 0,
    sphone: "",
    page: 1,
    infos: [{
      id: 0,
      startponit: "起运地址1",
      endpoint: "收货地址1",
      name: "产品1",
      weight: "300",
      tj: "34",
      num: "1",
      price: "3000",
      icheck: false,



    },
    {
      id: 1,
      startponit: "起运地址2",
      endpoint: "收货地址2",
      name: "产品2",
      weight: "300",
      tj: "34",
      num: "1",
      price: "3000",
      icheck: true

    },
    {
      id: 2,
      startponit: "起运地址3",
      endpoint: "收货地址3",
      name: "产品3",
      weight: "300",
      tj: "34",
      num: "1",
      price: "3000",
      icheck: false

    },
    {
      id: 3,
      startponit: "起运地址4",
      endpoint: "收货地址4",
      name: "产品4",
      weight: "300",
      tj: "34",
      num: "1",
      price: "3000",
      icheck: true

    },
    {
      id: 4,
      startponit: "起运地址5",
      endpoint: "收货地址5",
      name: "产品5",
      weight: "300",
      tj: "34",
      num: "1",
      price: "3000",
      icheck: false

    },
    {
      id: 5,
      startponit: "起运地址6",
      endpoint: "收货地址6",
      name: "产品6",
      weight: "300",
      tj: "34",
      num: "1",
      price: "3000",
      icheck: true

    },
    {
      id: 6,
      startponit: "起运地址7",
      endpoint: "收货地址7",
      name: "产品7",
      weight: "300",
      tj: "34",
      num: "1",
      price: "3000",
      icheck: false

    },
    {
      id: 7,
      startponit: "起运地址8",
      endpoint: "收货地址8",
      name: "产品8",
      weight: "300",
      tj: "34",
      num: "1",
      price: "3000",
      icheck: true

    },
    {
      id: 8,
      startponit: "起运地址9",
      endpoint: "收货地址9",
      name: "产品9",
      weight: "300",
      tj: "34",
      num: "1",
      price: "3000",
      icheck: false

    },
    {
      id: 9,
      startponit: "起运地址10",
      endpoint: "收货地址10",
      name: "产品10",
      weight: "300",
      tj: "34",
      num: "1",
      price: "3000",
      icheck: true

    },
    {
      id: 10,
      startponit: "起运地址11",
      endpoint: "收货地址11",
      name: "产品11",
      weight: "300",
      tj: "34",
      num: "3",
      price: "1000",
      icheck: true

    },
    {
      id: 11,
      startponit: "起运地址12",
      endpoint: "收货地址12",
      name: "产品12",
      weight: "300",
      tj: "34",
      num: "20",
      price: "9000",
      icheck: false

    },
    {
      id: 12,
      startponit: "起运地址13",
      endpoint: "收货地址13",
      name: "产品13",
      weight: "300",
      tj: "34",
      num: "34",
      price: "4000",
      icheck: false

    },
    {
      id: 13,
      startponit: "起运地址14",
      endpoint: "收货地址14",
      name: "产品14",
      weight: "300",
      tj: "34",
      num: "34",
      price: "5000",
      icheck: true

    },
    {
      id: 14,
      startponit: "起运地址15",
      endpoint: "收货地址15",
      name: "产品15",
      weight: "300",
      tj: "34",
      num: "34",
      price: "9000",
      icheck: false

    },
    {
      id: 15,
      startponit: "起运地址16",
      endpoint: "收货地址16",
      name: "产品16",
      weight: "300",
      tj: "34",
      num: "34",
      price: "3000",
      icheck: true

    },
    {
      id: 16,
      startponit: "起运地址17",
      endpoint: "收货地址17",
      name: "产品17",
      weight: "300",
      tj: "34",
      num: "34",
      price: "3000",
      icheck: false

    },],
    array: [{
      startaddress: "开始地点1",
      endaddress: "到达地点1",
      id: "1234567890",
      name: "产品",
      weight: "300",
      tj: "34",
      num: "34",
      price: "3000",
      state: "已完成"
    }, {
      id: 13,
      startaddress: "开始地点2",
      endaddress: "到达地点2",
      id: "1234567890",
      name: "产品",
      weight: "300",
      tj: "34",
      num: "34",
      price: "3000",
      state: "已完成"
    },
    {
      id: 14,
      startaddress: "开始地点3",
      endaddress: "到达地点3",
      id: "1234567890",
      name: "产品",
      weight: "300",
      tj: "34",
      num: "34",
      price: "3000",
      state: "已完成"
    },
    {
      id: 15,
      startaddress: "开始地点4",
      endaddress: "到达地点4",
      id: "1234567890",
      name: "产品",
      weight: "300",
      tj: "34",
      num: "34",
      price: "3000",
      state: "已完成"
    }]
    ,
    imgsrc: '0',
    clickid: -1,
    show: false,
    active: 0,
    show2: false,
    dd: '',
  },

  //下一步
  nextbtn: function () {
//this.data.nickname this.data.carnumber this.data.mobile
    if (this.data.nickname == "" || this.data.carnumber == "" || this.data.mobile=="") {
      wx.showToast({
        title: '请选择司机',
        icon: 'loading',
        duration: 1500
      })
      return;
    } else {
      console.log("--goodsinfo--" + this.data.goodsinfo);
      wx.navigateTo({
        url: '/pages/nextorder/nextorder?'
        + 'fhprovice=' + this.data.fhprovice + '&'
        + 'fhcity=' + this.data.fhcity + '&'
        + 'fharea=' + this.data.fharea + '&'
        + 'shprovice=' + this.data.shprovice + '&'
        + 'shcity=' + this.data.shcity + '&'
        + 'sharea=' + this.data.sharea + '&'
        + 'shaddress=' + this.data.shaddress + '&'
        + 'goodsinfo=' + this.data.goodsinfo + '&'
        + 'weight=' + this.data.weight + '&'
        + 'volume=' + this.data.volume + '&'
        + 'freight=' + this.data.freight + '&'
        + 'packnumber=' + this.data.packnumber + '&'
        + 'nickname=' + this.data.nickname + '&'
        + 'carnumber=' + this.data.carnumber + '&'
        + 'mobile=' + this.data.mobile + '&'
        + 'active=' + this.data.active + '&'
        + 'yfk=' + this.data.yfk + '&'
        + 'hdyj=' + this.data.hdyj

      })
    }

  },
  //   第一屏幕选择模板
  tabclick: function (res) {

    console.log(res);
    //   判断是不是激活状态
    if (res.currentTarget.id == this.data.clickid) {
      that.setData({
        clickid: -1,
        fhprovice: '',
        fhcity: '',
        fharea: '',


        shprovice: '',
        shcity: '',
        sharea: '',
        goodsinfo: '',
        weight: '',
        volume: '',
        freight: '',
        packnumber: '',
        active: 0,
      });
    } else {

      that.setData({
        clickid: res.currentTarget.id,

        fhprovice: res.currentTarget.dataset.fhprovice,
        fhcity: res.currentTarget.dataset.fhcity,
        fharea: res.currentTarget.dataset.fharea,

        shprovice: res.currentTarget.dataset.shprovice,
        shcity: res.currentTarget.dataset.shcity,
        sharea: res.currentTarget.dataset.sharea,

        //   货物
        goodsinfo: res.currentTarget.dataset.goodsinfo,
        //   重量
        weight: res.currentTarget.dataset.weight,
        //   占地
        volume: res.currentTarget.dataset.volume,
        //   金额
        freight: res.currentTarget.dataset.freight,
        //   个数
        packnumber: res.currentTarget.dataset.packnumber,
        //预付款
        yfk: res.currentTarget.dataset.yfk,
        //回单押金
        hdyj: res.currentTarget.dataset.hdyj,

        active: 1,
      });

    }

  },
  //   clickbtn: function(e){
  //       if()
  //   },
  tap_ch: function (e) {
    if (this.data.open) {
      this.setData({
        open: false
      });
    } else {
      this.setData({
        open: true
      });
    }
  },



  onLoad: function (options) {
    console.log(this.data.page + '---------------这是页吗')
    that = this;
    //   that.mobile = options.mobile;
    //   that.appkey = options.appkey;


    //   that.setData({
    //         mobile: options.mobile,
    //         appkey: options.appkey
    //   })
    var userinfos = wx.getStorageSync('userinfos');
    var mobile = userinfos.mobile;
    //   var appkey = userinfos.appkey;
    var myDate = new Date();

    var thistime = myDate.getTime();
    console.log(thistime)
    var appkey = app.globalData.appkey;
    console.log('----------------' + appkey)
    var appsecret = app.globalData.appsecret;

    console.log('----------------' + appsecret)
    var str = mobile + appsecret + thistime;

    console.log('----------------' + str)


    var appsign = utilMd5.md5(str);

    appsign = appsign.replace("+", "%2B");

    appsign = appsign.replace("=", "%2A");
    console.log(thistime)

    console.log(appsign + '-----------------------------appsign')
    wx.request({
      url: getApp().globalData.url,
      method: 'POST',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: Util.json2Form({
        mobile: mobile,
        appkey: appkey,
        viewtype: 3,
        pagesize: 10,
        page: that.data.page,
        appsign: appsign,
        date: thistime,

      }),
      success: function (res) {

        console.log(res.data);

        var r = JSON.parse(res.data.errorMsg);
        console.log("-----" + r);
        console.log(res.data);

        if (res.data.success) {
          that.setData({
            result: that.data.result.concat(r),
            page: that.data.page,
          });

        }


        //   console.log("------上啦--" + that.data.result);

      }
      //初始化的时候渲染wxSearchdata
      //   console.log(res.data.errorMsg);
      //   var  result =res.data;



    })



    app.editTabBar();//添加tabBar数据  
    wx.setNavigationBarTitle({
      title: '订单管理',
    })
    console.log('onLoad');




    //     WxSearch.init(that, 100, that.data.result);
    //     WxSearch.initMindKeys(that.data.result);


    var userinfos = wx.getStorageSync('userinfos');
    var mobile = userinfos.mobile;
    console.log("----个人中心--" + mobile);
    var appkey = userinfos.appkey;
    console.log("----个人中心--" + appkey);

    //  that.get(mobile, appkey);
    console.log("---mobile---" + that.data.mobile);
    console.log("---appkey---" + that.data.appkey);
    // that.getDriveNames();
    //调用应用实例的方法获取全局数据
    /**
* 获取系统信息
*/
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }
    });

  },
  nextpageTo: function (e) {
    console.log("跳转到下一步页面：");
    wx.redirectTo({
      url: '../nextorder/nextorder',
    })
  },


  clickitem: function (e) {
    var $icheck = e.currentTarget.dataset.icheck;
    //打印可以看到，此处已获取到了对应的id      var that = this;
    var $id = e.currentTarget.dataset.id;
    // let currentIndex = that.data.infos.findIndex(item => item.icheck === $id);
    // // console.log("当前小标：" + index);
    that.setData({
      ['infos[' + $id + '].icheck']: !$icheck
    }
    );
    console.log($id);


    console.log(e);
  },
  wxSearchFn: function (e) {
    that = this;
    console.log("-----wxSearchFn---");
    WxSearch.wxSearchAddHisKey(that);
  },
  wxSearchInput: function (e) {
    var that = this;
    console.log("-----wxSearchInput---");
    WxSearch.wxSearchInput(e, that);

  },
  wxSerchFocus: function (e) {
    that = this

    WxSearch.wxSearchFocus(e, that);
    console.log("-----wxSerchFocus---");
    that.getDriveNames();


    /*
    *
    调用司机列表
    */
  },
  select_car: function () {
    that.getDriveNames();

  },
  listenerPickerSelected: function (e) {
    //改变index值，通过setData()方法重绘界面
    this.setData({
      index: e.detail.value
    });
  },
  getssPhone: function (e) {
    this.setData({
      sphone: e.detail.value
    })
  },
  selectDrivers: function (e) {
    console.log("------<<<<<---点击了完成按钮-->>>>>");
    that = this;
    var userinfos = wx.getStorageSync('userinfos');
    var mobile = userinfos.mobile;
    var appkey = userinfos.appkey;
    console.log("----个人中心--" + mobile);

    console.log("----个人中心--" + appkey);
    console.log("--手机号：----" + mobile);
    console.log("---验证---" + appkey);
    var phone = that.data.sphone;
    console.log("-------检索的手机号号码----" + phone);
    wx.showToast({
      title: '加载中......',
      icon: "success"
    })
    var userinfos = wx.getStorageSync('userinfos');
    var mobile = userinfos.mobile;
    //     var appkey = userinfos.appkey;
    var myDate = new Date();

    var thistime = myDate.getTime();

    var appkey = app.globalData.appkey;

    var appsecret = app.globalData.appsecret;


    var str = mobile + appsecret + thistime;

    console.log('----------------' + str)


    var appsign = utilMd5.md5(str);

    appsign = appsign.replace("+", "%2B");

    appsign = appsign.replace("=", "%2A");


    console.log(appsign + '-----------------------------appsign')
    wx.request({
      url: getApp().globalData.url,
      method: 'POST',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: Util.json2Form({
        mobile: mobile,
        appkey: appkey,
        viewtype: 2,
        pagesize: 200,
        page: that.data.page,
        search: phone,
        appsign: appsign,
        date: thistime,
      }),
      success: function (res) {
        console.log(res.data);
        wx.hideLoading();
        var r = JSON.parse(res.data.errorMsg);
        console.log("-----" + r);

        that.setData({
          result: r
        });

        //初始化的时候渲染wxSearchdata
        console.log(res.data.errorMsg);
        // var  result =res.data;

        console.log("----" + that.data.result);
        for (var i = 0; i < that.data.result.length; i++) {
          console.log("===所有司机=" + that.data.result[i].nickname);

        }
      }
    })

  },
  getDriveNames: function () {
    that = this;
    var userinfos = wx.getStorageSync('userinfos');
    var mobile = userinfos.mobile;
    console.log("----个人中心--" + mobile);
    //     var appkey = userinfos.appkey;
    console.log("----个人中心--" + appkey);
    console.log("--手机号：----" + mobile);
    console.log("---验证---" + appkey);
    var myDate = new Date();

    var thistime = myDate.getTime();

    var appkey = app.globalData.appkey;

    var appsecret = app.globalData.appsecret;


    var str = mobile + appsecret + thistime;

    console.log('----------------' + str)


    var appsign = utilMd5.md5(str);

    appsign = appsign.replace("+", "%2B");

    appsign = appsign.replace("=", "%2A");


    console.log(appsign + '-----------------------------appsign')

    wx.request({
      url: getApp().globalData.url,
      method: 'POST',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: Util.json2Form({
        mobile: mobile,
        appkey: appkey,
        viewtype: 2,
        pagesize: 20,
        page: that.data.page,
        appsign: appsign,
        date: thistime,
      }),
      success: function (res) {
        console.log(res.data);
        var r = JSON.parse(res.data.errorMsg);
        console.log("-----" + r);

        that.setData({
          result: r
        });

        //初始化的时候渲染wxSearchdata
        console.log(res.data.errorMsg);
        // var  result =res.data;

        console.log("----" + that.data.result);
        for (var i = 0; i < that.data.result.length; i++) {
          console.log("===所有司机=" + that.data.result[i].nickname);

        }
      }
    })

  },

  //   wxSearchBlur: function (e) {
  //     var that = this
  //     WxSearch.wxSearchBlur(e, that);
  //     console.log("-----wxSearchBlur---");
  //   },
  //   wxSearchKeyTap: function (e) {
  //     var that = this
  //     WxSearch.wxSearchKeyTap(e, that);
  //     console.log("-----wxSearchKeyTap---");
  //   },
  //   wxSearchDeleteKey: function (e) {
  //     var that = this
  //     WxSearch.wxSearchDeleteKey(e, that);
  //     console.log("-----wxSearchDeleteKey---");
  //   },
  //   wxSearchDeleteAll: function (e) {
  //     var that = this;
  //     WxSearch.wxSearchDeleteAll(that);
  //     console.log("-----wxSearchDeleteAll---");
  //   },
  //   wxSearchTap: function (e) {
  //     var that = this
  //     WxSearch.wxSearchHiddenPancel(that);
  //     console.log("-----wxSearchTap---");
  //   },

  onShow: function (e) {


    var that = this;
    var userinfos = wx.getStorageSync('userinfos');
    var mobile = userinfos.mobile;
    console.log(mobile + '321111111111111111111111111')
    //   var appkey = userinfos.appkey;
    var myDate = new Date();

    var thistime = myDate.getTime();
    console.log(thistime)
    var appkey = app.globalData.appkey;
    console.log(appkey)
    var appsecret = app.globalData.appsecret;
    console.log(appsecret)

    var str = mobile + appsecret + thistime;

    console.log('----------------' + str)


    var appsign = utilMd5.md5(str);

    appsign = appsign.replace("+", "%2B");

    appsign = appsign.replace("=", "%2A");


    console.log(appsign + '-----------------------------appsign')
    wx.request({
      url: getApp().globalData.url,
      method: 'POST',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: Util.json2Form({
        mobile: mobile,
        appkey: appkey,
        viewtype: 3,
        pagesize: 10,
        page: that.data.page,
        appsign: appsign,
        date: thistime,

      }),
      success: function (res) {

        console.log(res.data);

        var r = JSON.parse(res.data.errorMsg);
        console.log("-----" + r);
        console.log(res.data);
        var r = JSON.parse(res.data.errorMsg);
        console.log("-----" + r);
        if (res.data.success) {
          that.setData({
            result: that.data.result.concat(r),
            page: that.data.page,
          });

        }


        //   console.log("------上啦--" + that.data.result);

      }
      //初始化的时候渲染wxSearchdata
      //   console.log(res.data.errorMsg);
      //   var  result =res.data;



    })
    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          windowHeight: res.windowHeight,
          windowWidth: res.windowWidth
        })
      }
    })
  },
  pullDownRefresh: function (e) {

    this.onLoad();
    wx.showToast({
      title: '刷新成功',
      icon: 'success',
      duration: 2000
    })
  },

  pullDownRefresh1: function (e) {

    this.onLoad()
    wx.showToast({
      title: '刷新成功',
      icon: 'success',
      duration: 2000
    })
  },
  //   pullUpLoad1: function (e){

  //     this.setData({
  //       page: this.data.page + 1
  //     })
  //     wx.showToast({
  //       title: '加载中.....',
  //       icon: "loading",
  //       duration: 2000
  //     })
  //     var userinfos = wx.getStorageSync('userinfos');
  //     var mobile = userinfos.mobile;
  //     console.log("----个人中心--" + mobile);
  //     var appkey = userinfos.appkey;
  //     console.log("----个人中心--" + appkey);
  //     console.log("--手机号：----" + mobile);
  //     console.log("---验证---" + appkey);
  //     wx.request({
  //       url: getApp().globalData.url,
  //       method: 'POST',
  //       header: {
  //         "Content-Type": "application/x-www-form-urlencoded"
  //       },

  //       data: Util.json2Form({
  //             mobile: mobile,
  //             appkey:appkey,
  //         viewtype: 3,
  //         pagesize: that.data.pagesize,
  //         page: that.data.page
  //       }),
  //       success: function (res) {
  //         console.log(res.data)
  //       //   var r = JSON.parse(res.data.errorMsg);
  //       //   console.log("-----" + r);
  //         if (res.data.success) {
  //           that.setData({
  //             result: that.data.result.concat(r),
  //             page: that.data.page,
  //           });
  //           wx.hideLoading();
  //         }
  //         //初始化的时候渲染wxSearchdata
  //         console.log(res.data.errorMsg);
  //         // var  result =res.data;
  //         console.log("----" + that.data.result);
  //         for (var i = 0; i < that.data.result.length; i++) {
  //           console.log("===所有司机=" + that.data.result[i].nickname);
  //         }
  //       }
  //     })
  //     console.log("上拉拉加载更多...." + this.data.page)

  // //    console.log("司机列表上拉加载。。。。。。。"+that.data.page);


  //   }
  //   ,


  pullUpLoad: function (e) {
    console.log(this.data.page + '-----------------------------------------这是页吗')
    this.setData({
      page: this.data.page + 1
    })

    console.log("上拉拉加载更多...." + this.data.page)
    wx.showToast({
      title: '加载中......',
      icon: 'loading',

    })
    that = this;
    var userinfos = wx.getStorageSync('userinfos');
    var mobile = userinfos.mobile;
    //     var appkey = userinfos.appkey;
    console.log(mobile + '这是下拉的mobilemobilemobile')
    var myDate = new Date();
    var thistime = myDate.getTime();
    var appkey = app.globalData.appkey;
    var appsecret = app.globalData.appsecret;
    var str = mobile + appsecret + thistime;
    console.log('----------------' + str)
    var appsign = utilMd5.md5(str);
    appsign = appsign.replace("+", "%2B");
    appsign = appsign.replace("=", "%2A");
    console.log(appsign + '-----------------------------appsign')
    wx.request({
      url: getApp().globalData.url,
      method: 'POST',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: Util.json2Form({
        mobile: mobile,
        appkey: appkey,
        viewtype: 3,
        pagesize: 10,
        page: that.data.page,
        appsign: appsign,
        date: thistime,

      }),
      success: function (res) {

        console.log(res.data);

        // var r = JSON.parse(res.data.errorMsg);
        console.log("-----" + r);
        console.log(res.data);
        var r = JSON.parse(res.data.errorMsg);
        console.log("-----" + r);

        if (res.data.success) {
          that.setData({
            result: that.data.result.concat(r),

            page: that.data.page,

          });
          wx.hideLoading();
        }


        console.log("------上啦--" + that.data.result);

      }
      // //初始化的时候渲染wxSearchdata
      // console.log(res.data.errorMsg);
      // var  result =res.data;



    })
    // this.getDataFromServer(this.data.page)
  },
  pullUpLoad1: function (e) {
    console.log(this.data.page + '-----------------------------------------这是页吗')
    this.setData({
      page: this.data.page + 1
    })

    console.log("上拉拉加载更多...." + this.data.page)
    wx.showToast({
      title: '加载中......',
      icon: 'loading',

    })
    that = this;
    var userinfos = wx.getStorageSync('userinfos');
    var mobile = userinfos.mobile;
    //   var appkey = userinfos.appkey;
    console.log("--手机号：----" + that.data.mobile);
    console.log("---验证---" + that.data.appkey);
    var myDate = new Date();

    var thistime = myDate.getTime();

    var appkey = app.globalData.appkey;

    var appsecret = app.globalData.appsecret;


    var str = mobile + appsecret + thistime;

    console.log('----------------' + str)


    var appsign = utilMd5.md5(str);

    appsign = appsign.replace("+", "%2B");

    appsign = appsign.replace("=", "%2A");


    console.log(appsign + '-----------------------------appsign')
    wx.request({
      url: getApp().globalData.url,
      method: 'POST',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: Util.json2Form({
        mobile: mobile,
        appkey: appkey,
        viewtype: 3,
        pagesize: 10,
        page: that.data.page,
        appsign: appsign,
        date: thistime,

      }),
      success: function (res) {

        console.log(res.data);

        // var r = JSON.parse(res.data.errorMsg);
        console.log("-----" + r);
        console.log(res.data);
        var r = JSON.parse(res.data.errorMsg);
        console.log("-----" + r);

        if (res.data.success) {
          that.setData({
            result: that.data.result.concat(r),

            page: that.data.page,

          });
          wx.hideLoading();
        }


        console.log("------上啦--" + that.data.result);

      }
      // //初始化的时候渲染wxSearchdata
      // console.log(res.data.errorMsg);
      // var  result =res.data;



    })
    // this.getDataFromServer(this.data.page)
  },
  /**
        * 滑动切换tab
        */
  bindChange: function (e) {
    var that = this;
    that.setData({ currentTab: e.detail.current });
  },
  getHistoryOrder: function (mobile, appsecret) {
    wx.showToast({
      title: '加载中......',
      icon: 'loading',

    })
    that = this;
    var userinfos = wx.getStorageSync('userinfos');
    var mobile = userinfos.mobile;
    //     var appkey = userinfos.appkey;
    console.log("--手机号：----" + mobile);
    console.log("---验证---" + appsecret);
    var myDate = new Date();

    var thistime = myDate.getTime();

    var appkey = app.globalData.appkey;

    var appsecret = app.globalData.appsecret;


    var str = mobile + appsecret + thistime;

    console.log('----------------' + str)


    var appsign = utilMd5.md5(str);

    appsign = appsign.replace("+", "%2B");

    appsign = appsign.replace("=", "%2A");


    console.log(appsign + '-----------------------------appsign')
    wx.request({
      url: getApp().globalData.url,
      method: 'POST',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: Util.json2Form({
        mobile: mobile,
        appkey: appkey,
        viewtype: 3,
        pagesize: 10,
        page: that.data.page,
        appsign: appsign,
        date: thistime,

      }),
      success: function (res) {
        wx.hideLoading();
        console.log(res.data);
        var r = JSON.parse(res.data.errorMsg);
        console.log("-----" + r);

        that.setData({
          result: r
        });
        // //初始化的时候渲染wxSearchdata
        // console.log(res.data.errorMsg);
        // var  result =res.data;


      }
    })
  },
  /**
   * 点击tab切换
   */
  swichNav: function (e) {
    var that = this;
    console.log("---swichNav----" + this.data.currentTab);
    if (this.data.currentTab == 0) {
      /*
      *历史订单
      */
      var userinfos = wx.getStorageSync('userinfos');
      var mobile = userinfos.mobile;
      var userinfos = wx.getStorageSync('userinfos');
      var mobile = userinfos.mobile;
      console.log("----个人中心--" + mobile);
      var appkey = userinfos.appkey;
      console.log("----个人中心--" + appkey);
      console.log("----个人中心--" + that.mobile);
      // var appkey = userinfos.appkey;
      console.log("----个人中心--" + that.appkey);
      that.getHistoryOrder(mobile,appkey);

    }
    if (this.data.currentTab == 1) {
      // var mobile = userinfos.mobile;
      // var userinfos = wx.getStorageSync('userinfos');
      // var mobile = userinfos.mobile;
      // console.log("----个人中心--" + mobile);
      // var appkey = userinfos.appkey;
      // wx.showToast({
      //   title: '加载中.....',
      //   icon: "loading",

      // })
      // console.log("--手机号：----" + that.mobile);
      // console.log("---验证---" + that.appkey);
      // that.setData({
      //   mobile: mobile,
      //   appkey: appkey
      // })
      // wx.request({
      //   url: 'https://bmc.huochexia.com/business/v1.0/wechat/getalldata',
      //   method: 'POST',
      //   header: {
      //     "Content-Type": "application/x-www-form-urlencoded"
      //   },

      //   data: Util.json2Form({
      //     mobile: mobile,
      //     appkey: appkey,
      //     viewtype: 2,
      //     pagesize: 25,
      //     page: that.data.page
      //   }),
      //   success: function (res) {
      //     console.log(res.data);
      //     wx.hideLoading();
      //     var r = JSON.parse(res.data.errorMsg);
      //     console.log("-----" + r);
      //     if (res.data.success) {
      //       that.setData({
      //         result: r,

      //       });
      //       wx.hideLoading();
      //     }
      //     //初始化的时候渲染wxSearchdata
      //     console.log(res.data.errorMsg);
      //     // var  result =res.data;
      //     console.log("----" + that.data.result);
      //     for (var i = 0; i < that.data.result.length; i++) {
      //       console.log("===所有司机=" + that.data.result[i].nickname);
      //     }
      //   }
      // })
      // console.log("上拉拉加载更多...." + this.data.page)

      // console.log("司机列表上拉加载。。。。。。。" + that.data.page);


    }
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },


  //   搜索 接口数据返回10条 需要弄清接口默认返回多少
  getsPhone: function (res) {
    console.log(res);
    this.setData({
      phoneval: res.detail.value,
      na: res.detail.value.length
    })

    var userinfos = wx.getStorageSync('userinfos');
    var mobile = userinfos.mobile;
    //   var appkey = userinfos.appkey;
    var myDate = new Date();

    var thistime = myDate.getTime();

    var appkey = app.globalData.appkey;

    var appsecret = app.globalData.appsecret;


    var str = mobile + appsecret + thistime;

    console.log('----------------' + str)


    var appsign = utilMd5.md5(str);

    appsign = appsign.replace("+", "%2B");

    appsign = appsign.replace("=", "%2A");


    console.log(appsign + '-----------------------------appsign')
    console.log(this.data.phoneval.length + '=====================length')
    if (this.data.phoneval.length != 0) {
      this.setData({
        show: true

      });
      console.log(this.data.phoneval + "这是我的搜索内容");
      // 发送请求
      wx.request({
        url: getApp().globalData.url,
        method: 'POST',
        header: {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        data: Util.json2Form({
          mobile: mobile,
          appkey: appkey,
          viewtype: 2,
          pageSize: 100,//不起作用
          page: 1,
          search: this.data.phoneval,
          appsign: appsign,
          date: thistime,

        }),
        success: res => {
          console.log(res);
          var r = JSON.parse(res.data.errorMsg);
          console.log("-----" + r);
//
          this.setData({
            srklist: r,
          });
          console.log(this.data.srklist)
        }
      });
    } else {
      this.setData({
        show: false,
        srklist: '',
        nickname: '',
        carnumber: '',
        mobile: '',
      });

    }
  },
  tj: function (res) {
    console.log(res);
    this.setData({
      phoneval: res.currentTarget.dataset.nr,
      show: false,
      srklist: '',
      nickname: res.currentTarget.dataset.nr,
      carnumber: res.currentTarget.dataset.carnumber,
      mobile: res.currentTarget.dataset.mobile,
    });

  },
  getsdd: function (res) {
    console.log(res);
    this.setData({
      dd: res.detail.value,
      ddlen: res.detail.cursor,
      page: 1,
    })
    console.log('--------------------------' + this.data.dd);
    var userinfos = wx.getStorageSync('userinfos');
    var mobile = userinfos.mobile;
    //   var appkey = userinfos.appkey;
    var myDate = new Date();

    var thistime = myDate.getTime();

    var appkey = app.globalData.appkey;

    var appsecret = app.globalData.appsecret;


    var str = mobile + appsecret + thistime;

    console.log('----------------' + str)


    var appsign = utilMd5.md5(str);

    appsign = appsign.replace("+", "%2B");

    appsign = appsign.replace("=", "%2A");


    console.log(appsign + '-----------------------------appsign')

    if (this.data.ddlen != 0) {

      console.log(this.data.page + "dddddddddddddddddddddddd这是page");
      console.log(this.data.page)
      // 发送请求
      wx.request({
        url: getApp().globalData.url,
        method: 'POST',
        header: {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        data: Util.json2Form({
          mobile: mobile,
          appkey: appkey,
          viewtype: 3,
          pagesize: 20,
          page: this.data.page,
          code: this.data.dd,
          appsign: appsign,
          date: thistime,

        }),
        success: res => {
          console.log(res);
          var r = JSON.parse(res.data.errorMsg);
          console.log("-----" + r);

          this.setData({
            result: r,
          });
          console.log(this.data.result)
        }
      });
    }
  },
  //   tj2: function (res) {
  //         console.log(res);
  //         this.setData({
  //               phoneval: res.currentTarget.dataset.nr,
  //               show: false,
  //               srklist: '',
  //               nickname: res.currentTarget.dataset.nr,
  //               carnumber: res.currentTarget.dataset.carnumber,
  //               mobile: res.currentTarget.dataset.mobile,
  //         });

  //   },

})

